package com.heima.tessj;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;

import java.io.File;

public class Application {
    public static void main(String[] args) {
        try {
            //1.创建对象
            ITesseract tesseract = new Tesseract();
            //2.设置字体库
            tesseract.setDatapath("/opt/homebrew/Cellar/tesseract/5.3.0_1/share/tessdata/");
            //3.设置语言
            tesseract.setLanguage("chi_sim");

            File file = new File("/Users/zqr/develop/TestResource/test.png");
            //4.识别图片
            String result = tesseract.doOCR(file);
            //5.获取结果
            result = result.replaceAll("\\r|\\n","-").replaceAll(" ","");
            System.out.println("识别的结果为："+result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
